package org.seamon.management.util;

import lombok.Data;
import org.seamon.management.util.enums.ErrorCodeEnum;

@Data
public class Result<T> {
    private Integer code;
    private String message;
    private Object data;

    public static Result<?> success() {
        Result<?> result = new Result<>();
        result.setCode(200);
        result.setMessage("操作成功");
        return result;
    }
    public static Result<?> success(Object data) {
        Result<?> result = success();
        result.setData(data);
        return result;
    }

    public static Result<?> error(ErrorCodeEnum errorCodeEnum) {
        Result<?> result = new Result<>();
        result.setCode(errorCodeEnum.getCode());
        result.setMessage(errorCodeEnum.getMessage());
        return result;
    }

    public static Result<?> error(Integer code, String message) {
        Result<?> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }
}
